package com.example.apione.controller.admin;

import com.alibaba.fastjson2.JSONObject;
import com.example.apione.dao.ApiInfoDao;
import com.example.apione.dao.WebInfoDao;
import com.example.apione.model.Webinfomodel;
import com.example.apione.model.addApimodel;
import com.example.apione.utils.ResponseResult;
import lombok.Data;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 尘落
 * @date 2023/2/24
 */
@Data
@RestController
public class addApi {
    private final ApiInfoDao apiInfoDao;
    private final WebInfoDao webInfoDao;
    @PostMapping("api/addpai")
    public ResponseResult<String> addpai(@RequestBody JSONObject jsonObject) {
        String msg=addApimodel.addapi(apiInfoDao,jsonObject);
        if (msg.equals("ok")){
            return ResponseResult.ok("添加成功！");
        }else if (msg.equals("已存在")){
            return ResponseResult.fail("已存在！");
        }
        return ResponseResult.fail("添加失败！");
    }
    @PostMapping("api/uppai")
    public ResponseResult<String> uppai(@RequestBody JSONObject jsonObject) {
        String msg=addApimodel.upapi(apiInfoDao,jsonObject);
        if (msg.equals("ok")) {
            return ResponseResult.ok("修改成功！");
        }
        return ResponseResult.fail("修改失败！");
    }

    @PostMapping("api/upwebinfo")
    public ResponseResult<String> upweb(@RequestBody JSONObject jsonObject) {
        String msg= Webinfomodel.setinfo(webInfoDao,jsonObject);
        if (msg.equals("ok")){
            return ResponseResult.ok("添加成功！");
        }
        return ResponseResult.fail("添加失败！");

    }

    @PostMapping("api/delapi")
    public ResponseResult<String> delapi(@RequestBody JSONObject jsonObject) {
        String msg= addApimodel.delapi(apiInfoDao,jsonObject);
        if (msg.equals("ok")){
            return ResponseResult.ok("删除成功！");
        }
        return ResponseResult.fail("删除失败！");

    }
}
